const app = getApp()
var tips;
Page({
  data: {
    motto: '',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    avatar: '',
    nickname: '',
    list:[{
      num:"10",
      money:"50",
      cates:"3",
      id:"2"
    }],
  },
  //事件处理函数  
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }

    var that = this;
    var openid = app.whereId.openid; //openid;
    var shopid = app.whereId.shopid;

    // var avatar = app.userInfo.avatar;
    app.userInfo.avatar = wx.getStorageSync('avater');
    var avatar = app.userInfo.avatar;

    app.userInfo.user_nicename = wx.getStorageSync('nickname');
    var nickname = app.userInfo.user_nicename; 
    
    console.log(nickname); console.log('*---*');

    // console.log("这里是" + openid)
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/my/index',
      data: {
        openid: openid,
        shopid:shopid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        that.setData({
          list: res.data.list,
          idss: res.data.idss,
          avatar:avatar,
          nickname: nickname,
        });
      },
    })

  },

  onShow: function () {
    if (this.data.navigateToNextDelta) {
        this.onLoad();
    }
  },

  getUserInfo: function(e) {
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  stap: function (e) {
    var tips = e.currentTarget.dataset.id;
    var uid = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: "/pages/yiguo/record/record?tips=" + tips + "&cuid=" + uid,
    })
  }, 
  skip: function (e) {
    var ids = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/yiguo/rite/rite?id=" + ids
    })
  },
/** *  中间五个订单按钮  */
// 所有订单
  all_order:function(e){
    this.data.navigateToNextDelta = true
    var tips = 0;
    wx.navigateTo({
      url: "/pages/yiguo/record/record?tips=" + tips
    })
  },
// 待付款
  daifu: function (e) {
    this.data.navigateToNextDelta = true
    var tips = 1;
    wx.navigateTo({
      url: "/pages/yiguo/record/record?tips=" + tips
    })
  },
// 待发货
  daifa: function (e) {
    var tips = 2;
    this.data.navigateToNextDelta = true
    wx.navigateTo({
      url: "/pages/yiguo/record/record?tips=" + tips
    })
  },
// 待收货
  daishou: function (e) {
    this.data.navigateToNextDelta = true
    var tips = 3;
    wx.navigateTo({
      url: "/pages/yiguo/record/record?tips=" + tips
    })
  },
// 待评价
  pingjia: function (e) {
    var tips = 4;
    wx.navigateTo({
      url: "/pages/yiguo/record/record?tips=" + tips
    })
  },
// 待退款
  tuikuan: function (e) {
    this.data.navigateToNextDelta = true
    wx.navigateTo({
      url: "/pages/yiguo/refund-3/refund-3"
    })
  },
/**/

  //我的收藏
  shoucang: function (e) {
    var ids = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/yiguo/rite/rite?id=" + ids,
    })
  },

  //我的收货地址
  shouhuo: function (e) {
    var ids = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/yiguo/address/address?ids=" + ids,
    })
  },

  //我的信息页面
  xinxi:function(){
    wx.navigateTo({
      url: "/pages/yiguo/editer/editer",
    })
  }

})
